export {}
//keyof用法

// keyof用法示例
type K1 = keyof boolean; // 'valueof'
type K2 = keyof any;// string | number | symbol
type K3 = keyof number;// "toFixed" | "toExponential" | "toPrecision" | "toString" | "valueOf" | "toLocaleString"
type K4 = keyof string; // "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | ... 28 more ... | "valueOf"


enum HttpMethods {
  Get,
  Post,
  Put,
  Delete
};

type K5 = keyof typeof HttpMethods;// "Get" | "Post" | "Put" | "Delete"


// 基于keyof实现的Partial、Required、Pick、Record工具类型的内在实现
type Partial<T> = {
  [K in keyof T]?: T[K]
};

type Required<T> = {
  [K in keyof T]-?: T[K];
}

type Pick<T, U extends keyof T> = {
  [K in U]: T[K]
};

type Record<T extends keyof any, U> {
  [key: T]: U;
}


// keyof在泛型函数中的典型应用
type user5 = {
  name: string;
  age: number;
  boo: boolean;
}
type ValueType<T, U> = T extends keyof U ? U[T] : never;
function fn3(obj: user5, key: keyof user5): ValueType<keyof user5, user5> {
  return obj[key];
}